
  	layui.use(['element','form','upload'],function(){
  		var element=layui.element
  		,form=layui.form
  		,$ = layui.$
  		,upload = layui.upload;
  		
  		
//		var token = $.cookie("access_token");
//		console.log(token);
  		//获取用户名,性别,生日,银行卡号和银行卡图片
		$.ajax({
			type:"post",
			url:urlHead + "/Json/getDetailUserInfo",
			headers:{
        		"Authorization":$.cookie("access_token")
   			},
			async:false,//同步才能赋值全局变量
			success:function(res){
				console.log("用户的详细信息:");
				console.log(res);
				if(res.code==0){
					$('#username').val(res.data.name);//用户名
					$('#nickname').val(res.data.nickname);
					var IDcard = res.data.identityCardNum;//身份证号
	//				console.log(IDcard);
					showBirthdayAndSex(IDcard,"sex","birthday");//根据身份证号解析性别和生日
					if(res.data.state==0){//邮箱未激活
						$('#judgeemail').html('<a href="" class="layadmin-link">激活邮箱</a>');
					}else if(res.data.state==1){//邮箱已激活
						$('#judgeemail').html('<input type="text" name="email" id="email" readonly class="layui-input"/>');
						$('#email').val(res.data.email);
					}
					$('#bankcardno').val(res.data.bankCarbum);//银行卡号
	//				console.log(res.data.bankCarPath);
					$('#LAY_avatarSrc').val(res.data.bankCarPath);
				}else if(res.code==600602){//用户未登录
					layer.msg('用户未登录，请先登录',{icon:5},function(){
						location.href = "../../views/user/login_by_username.html";
					});
				}else if(res.code==600603){//token过期
					layer.msg('token已过期，请重新登录',{icon:5},function(){
						location.href = "../../views/user/login_by_username.html";
					});
				}
				
			}
		});
		
//		var bankCarPath1 = $('#LAY_avatarSrc').val();
//		console.log("银行卡图片地址1："+bankCarPath1);
		//获取银行卡图片
		$.ajax({
			type:"POST",
			url:urlHead + "/head/show",
			headers:{
				"Authorization":$.cookie("access_token")
			},
			async:true,
			data:{"fileName":$('#LAY_avatarSrc').val()},
			success:function(res){
				console.log("银行卡图片的地址:");
				console.log(res);
//				if(res.code==0){
//					
//				}
			}
		});

  		//监听提交个人信息
	  	form.on('submit(information)',function(data){
		  	var field = data.field,
		  	nickname = field.nickname;					//昵称	
		  	console.log("昵称:");
		  	console.log(nickname);
		  	
		  	$.ajax({
		  		type:"post",
		  		url:urlHead + "/modify/modifyNickname",
		  		headers:{
        		"Authorization":$.cookie("access_token")
   				},
		  		async:true,
		  		data:{"nickname":nickname},
		  		success:function(res){
		  			console.log("设置昵称结果:");
		  			console.log(res);
		  			if(res.code==0){
		  				layer.msg('信息提交成功',{icon:6});
		  			}else{
		  				layer.msg(res.msg,{icon:5});
		  			}
		  		},
		  		error:function(){
		  			layer.msg('信息提交失败',{icon:5});
		  		},
		  		dataType:"json"
		  	})
		  	return false;
	  	});
  		
  		//上传头像
  		upload.render({
  		 	 elem:'#upload-head-img',
  		 	 url:urlHead + '/head/fileUploadHead',
  		 	 headers:{
            	"Authorization":$.cookie('access_token')
        	},
  		 	 before:function(obj){
  		 	 	//预览
  		 	 	obj.preview(function(index,file,result){
		 	 		$('#head-img').attr('src',result);
  		 	 	});
  		 	 },
  		 	  done:function(res){//上传接口请求成功的回调函数
  		 	 		console.log("上传头像结果:");
  		 	 		console.log(res);
  		 	 		if(res.code==0){
  		 	 			layer.msg('头像上传成功',{icon:6});
  		 	 		}else{
  		 	 			layer.msg(res.msg,{icon:5});
  		 	 		}
  		 	 }
  		 });
  		 
 		
  	});